﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using DataLib.Accounts.Bus;

namespace Ewts.Storage
{
    public partial class VehicleArrangePaint1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request["cjoid"] != null && Request["cjoid"].ToString().Trim() != "")
                {
                    BindData(int.Parse(Request["cjoid"].ToString().Trim()));
                }
                else if (Request["outid"] != null && Request["outid"].ToString().Trim() != "")
                {
                    BindOutData(int.Parse(Request["outid"].ToString().Trim()));
                }
            }
        }

        protected void BindOutData(int outid)
        {
            DataLib.Model.OutStorage outmodel = new DataLib.BLL.OutStorage().GetModel(outid);
            lblCity.Text = outmodel.graphicCity;
            lblLoadNum.Text = outmodel.VLoadNum;
            lblCJO.Text = outmodel.outStorageNo;
            string cjoid = "0";
       
            DataLib.BLL.InStorage insBll = new DataLib.BLL.InStorage();
            //根据出库单获取入库的CJO ID
            DataTable barDt = new DataLib.BLL.BarCode().GetList("OutStrorageID=" + outid).Tables[0];
            DataLib.BLL.CJOItem cjoBll = new DataLib.BLL.CJOItem();
            DataLib.Model.CJOItem cjoModel = new DataLib.Model.CJOItem();
            if (barDt != null && barDt.Rows.Count > 0 && barDt.Rows[0]["cjoid"]!=null && barDt.Rows[0]["cjoid"].ToString().Trim() !="0")
            {
                cjoid = barDt.Rows[0]["cjoid"].ToString();
                cjoModel = cjoBll.GetListByCid(int.Parse(cjoid));
                lblCustomerCode.Text = cjoModel.customercode;
                lblCustomerContactor.Text = outmodel.graphicCity;
                lblCompanyName.Text = cjoModel.companyname;
                lblGoodsWeight.Text = outmodel.totalWeight.ToString();
            }

        }

        protected void BindData(int cjoid)
        {
            DataLib.Model.CJOItem cjomodel = new DataLib.BLL.CJOItem().GetListByCid(cjoid);
            string peReq = "";
            string matReq = "";
            string wasType = "";
            lblCity.Text = cjomodel.Graphicy;
            lblCJO.Text = cjomodel.cjono;
            lblCustomerCode.Text = cjomodel.customercode;
            lblCompanyName.Text = cjomodel.companyname;
            lblCollectDate.Text = cjomodel.CjoColldate.ToString();
            lblGoodsCount.Text = cjomodel.numberestimate.ToString();
            lblNoticeDate.Text = cjomodel.createtime.ToString();
            lblSamplingRequire.Text = cjomodel.samplingrequire;
            lblWorkerCount.Text = cjomodel.workercount.ToString();
            lblTools.Text = cjomodel.tools.ToString();
            if(cjomodel.peculiarrequire != null && cjomodel.peculiarrequire.Trim() != "")
            {
                string[] str = cjomodel.peculiarrequire.Split(';');
                for(int i =0; i< str.Length; i++)
                {
                    if(str[i] != "")
                    {
                        peReq += str[i];
                        peReq += "　　　";
                    }
                }
            }
            lblPeculiarRequire.Text = peReq;

            if (cjomodel.maternrequire != null && cjomodel.maternrequire.Trim() != "")
            {
                string[] str1 = cjomodel.maternrequire.Split(';');
                for (int i = 0; i < str1.Length; i++)
                {
                    if (str1[i] != "")
                    {
                        matReq += str1[i];
                        matReq += "　　　";
                    }
                }
            }
            lblMaternRequire.Text = matReq;

            //通过loadnumid拿到对应的LoadNum信息
            DataLib.Model.LoadNum loadM = new DataLib.BLL.LoadNum().GetModel(cjomodel.loadnumid);
            lblLoadNum.Text = loadM.loadnum;
            
            //2015年4月18日 22:07:50 FIFA  这里应该是预测重量
            lblGoodsWeight.Text = cjomodel.predictweight.ToString();   //loadM.totalWeight.ToString();
            lblGoodsInfo.Text = cjomodel.goodsdesc;
            lblSaleMan.Text = cjomodel.cjoshowmantruename;
            lblWasteDisposePlace.Text = loadM.Rubbisharea;
            if(loadM.RubbishType != null && loadM.RubbishType.Trim() != "")
            {
                string[] str2 = loadM.RubbishType.Split(';');
                for(int i =0; i< str2.Length; i++)
                {
                    if(str2[i] != "")
                    {
                        wasType += str2[i];
                        wasType += "　　　";
                    }
                }
            }
            lblWasteType.Text = wasType;

            //通过customerid拿到对应的客户信息
            DataLib.Model.Cumtomer cumModel = new DataLib.BLL.Cumtomer().GetModel((int)loadM.customerid);
            lblCustomerContactor.Text = cjomodel.cjolinkman;
            lblCustomerPhoneNum.Text = cjomodel.cjophone;

            //通过addressid拿到对应的地址信息
           // DataLib.Model.CumtomerAddress cumAddM = new DataLib.BLL.CumtomerAddress().GetModel((int)loadM.addressid);
            lblCollectAddress.Text = cjomodel.cjoaddinfo;

            //通过cjono拿到收货员的信息和车牌号的信息
            DataLib.BLL.VehicleArrange vehicleBll = new DataLib.BLL.VehicleArrange();
            DataLib.Model.VehicleArrange vehicleModel = vehicleBll.GetModelByCjoid(int.Parse(Request["cjoid"]));

            DataLib.BLL.Vehiclor vehiclorBll = new DataLib.BLL.Vehiclor();
            DataLib.Model.Vehiclor vehiclorModel = new DataLib.Model.Vehiclor();
            
            //当vehicleModel对象为空时，执行下面代码会报错， 特此做为空验证  2013.04.19 梁玲
            string vehiclorName = "";
            if (vehicleModel != null)
            {
                string[] arr = vehicleModel.vehiderid.Split(',');
                for (int i = 0; i < arr.Length; i++)
                {
                    if (arr[i] != "")
                    {
                        vehiclorModel = vehiclorBll.GetModel(int.Parse(arr[i]));
                        vehiclorName += vehiclorModel.name;
                        vehiclorName += "　　　";
                    }
                }
                DataLib.BLL.PlateNumber plateBll = new DataLib.BLL.PlateNumber();
                DataLib.Model.PlateNumber plateModel = new DataLib.Model.PlateNumber();
                string plateNumInfo = "";

                string[] brr = vehicleModel.platenumberid.Split(',');
                for (int i = 0; i < brr.Length; i++)
                {
                    if (brr[i] != "")
                    {
                        plateModel = plateBll.GetModel(int.Parse(brr[i]));
                        plateNumInfo += new DataLib.BLL.TransportCompany().GetModel(plateModel.transportIid).companyname + "--" + plateModel.maxton + "--" + plateModel.plateno;
                        plateNumInfo += "　　　";
                    }
                }
                lblVehiclor.Text = vehiclorName;
                lblPlateNum.Text = plateNumInfo;

                int count = 0;
                string[] veh = plateNumInfo.Split('　');
                for (int num = 0; num < veh.Length; num++)
                {
                    if (veh[num] != "")
                    {
                        count++;
                    }
                }
                lblVehiCount.Text = count.ToString();

            }
            //通过cjoid拿到车辆需求信息
            DataSet ds = new DataLib.BLL.VehicleRequire().GetList("cjoid='" + cjoid + "'");
            if (ds.Tables[0].Rows.Count > 0)
            {
                DataRow dr = ds.Tables[0].Rows[0];
                lblPayType.Text = dr["clearingform"].ToString();
                lblOtherRequire.Text = dr["otherrequire"].ToString();
                //lblVehiCount.Text = dr["vehiclecount"].ToString();
            }

            DataLib.Model.Cjo cjo = new DataLib.BLL.Cjo().GetModel(cjoid);
            lblCustomerContactor.Text = cjo.cjolinkman;
            lblCustomerPhoneNum.Text = cjo.cjophone;
       
            
        }

        /// <summary>
        /// 绑定收货员及车牌号
        /// </summary>
        /// <param name="flag">1为CJO 2为OUT</param>
        /// <param name="srcid"></param>
        public void BindPlateNumInfo(int srcid, int flag)
        {
            //通过cjono拿到收货员的信息和车牌号的信息
            DataLib.BLL.VehicleArrange vehicleBll = new DataLib.BLL.VehicleArrange();
            DataLib.Model.VehicleArrange vehicleModel = new DataLib.Model.VehicleArrange();

            if (flag == 1)
                vehicleModel = vehicleBll.GetModelByCjoid(srcid);
            else
                vehicleModel = vehicleBll.GetModelByOutid(srcid);

            DataLib.BLL.Vehiclor vehiclorBll = new DataLib.BLL.Vehiclor();
            DataLib.Model.Vehiclor vehiclorModel = new DataLib.Model.Vehiclor();


   
            string vehiclorName = "";
            if (vehicleModel != null)
            {
                string[] arr = vehicleModel.vehiderid.Split(',');
                for (int i = 0; i < arr.Length; i++)
                {
                    if (arr[i] != "")
                    {
                        vehiclorModel = vehiclorBll.GetModel(int.Parse(arr[i]));
                        vehiclorName += vehiclorModel.name;
                        vehiclorName += "　　　";
                    }
                }
                DataLib.BLL.PlateNumber plateBll = new DataLib.BLL.PlateNumber();
                DataLib.Model.PlateNumber plateModel = new DataLib.Model.PlateNumber();
                string plateNumInfo = "";

                string[] brr = vehicleModel.platenumberid.Split(',');
                for (int i = 0; i < brr.Length; i++)
                {
                    if (brr[i] != "")
                    {
                        plateModel = plateBll.GetModel(int.Parse(brr[i]));
                        plateNumInfo += new DataLib.BLL.TransportCompany().GetModel(plateModel.transportIid).companyname + "--" + plateModel.maxton + "--" + plateModel.plateno;
                        plateNumInfo += "　　　";
                    }
                }
                lblVehiclor.Text = vehiclorName;
                lblPlateNum.Text = plateNumInfo;

                int count = 0;
                string[] veh = plateNumInfo.Split('　');
                for (int num = 0; num < veh.Length; num++)
                {
                    if (veh[num] != "")
                    {
                        count++;
                    }
                }
                lblVehiCount.Text = count.ToString();

            }
        }

    }
}